axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
import Fun from "../../../fun/index";
let i = Fun.getKeyByI();
// let type = Fun.getTyep();
let uuid = window.localStorage.uuid;
if (!uuid) {
  uuid = 0;
}
// let baseUrl = "/addons/yun_shop/api.php?i=" + i + "&type=" + type + "&route=";
let loginUrl = Fun.getSiteRoot() + "/addons/yun_shop/" + "?menu#" + "/subplatformLogin?i=" + Fun.getKeyByI() + "&type=" + Fun.getTyep();
export default {
  // 封装axios的post请求
  post(url, params, message,type_pc) {
    let type = type_pc ? type_pc : Fun.getTyep();
    let baseUrl = "/addons/yun_shop/api.php?i=" + i + "&type=" + type + "&route=";
    url = baseUrl + url;
    return new Promise((resolve, reject) => {
      axios
        .post(url, { ...params })
        .then(({ data }) => {
          if (data.result) {
            resolve(data);
          } else {
            reject({...data,loginUrl});
          }
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  pc_post(url, params, message,type_pc) {
    let type = type_pc ? type_pc : Fun.getTyep();
    let baseUrl = "/addons/yun_shop/api.php?i=" + i + "&type=" + type + "&route=";
    url = baseUrl + url;
    return new Promise((resolve, reject) => {
      axios
        .post(url, { ...params })
        .then(({ data }) => {
          if (data.result) {
            resolve(data);
          } else {
            resolve({...data,loginUrl});
          }
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  // 封装axios的get请求
  get(url, params, message,type_pc) {
    let type = type_pc ? type_pc : Fun.getTyep();
    let baseUrl = "/addons/yun_shop/api.php?i=" + i + "&type=" + type + "&route=";
    url = baseUrl + url;
    return new Promise((resolve, reject) => {
      axios
        .get(url, { ...params })
        .then(({ data }) => {
          if (data.result) {
            resolve(data);
          } else {
            reject({...data,loginUrl});
          }
        })
        .catch(err => {
          reject(err);
        });
    });
  },
};
